1 Imports System.Data.OleDb
2 Public Class frmTable
3
4 Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
5 Me.Close()
6 End Sub
7 Sub Reset()
8 txtTableNo.Text = ""
9 cmbTableType.SelectedIndex = -1
10 btnSave.Enabled = True
11 btnDelete.Enabled = False
12 btnUpdate.Enabled = False
13 btnActivate_Deactivate.Enabled = False
14 btnActivate_Deactivate.Text = "Activate/Deactivate"
15 txtTableNo.Focus()
16 End Sub
17 Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
18 Reset()
19 End Sub
20 Sub fillInventoryType()
21 Try
22 Dim CN As New OleDbConnection(cs)
23 CN.Open()
24 adp = New OleDbDataAdapter()
25 adp.SelectCommand = New OleDbCommand("SELECT distinct RTRIM(Type) FROM InventoryType order by 1", CN)
26 ds = New DataSet("ds")
27 adp.Fill(ds)
28 Dim dtable As DataTable = ds.Tables(0)
29 cmbTableType.Items.Clear()
30 For Each drow As DataRow In dtable.Rows
31 cmbTableType.Items.Add(drow(0).ToString())
32 Next
33 Catch ex As Exception
34 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
35 End Try
36 End Sub
37 Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
38 If txtTableNo.Text = "" Then
39 MessageBox.Show("Please enter table no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
40 txtTableNo.Focus()
41 Return
42 End If
43 If cmbTableType.Text = "" Then
44 MessageBox.Show("Please select table type", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
45 cmbTableType.Focus()
46 Return
47 End If
48 Try
49 con = New OleDbConnection(cs)
50 con.Open()
51 Dim ct As String = "select TableNo from R_Table where TableNo=@d1"
52 cmd = New OleDbCommand(ct)
53 cmd.Parameters.AddWithValue("@d1", txtTableNo.Text)
54 cmd.Connection = con
55 rdr = cmd.ExecuteReader()
56
57 If rdr.Read() Then
58 MessageBox.Show("Table No. Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
59 txtTableNo.Text = ""
60 txtTableNo.Focus()
61 If (rdr IsNot Nothing) Then
62 rdr.Close()
63 End If
64 Return
65 End If
66 con = New OleDbConnection(cs)
67 con.Open()
68 Dim cb As String = "insert into R_Table(TableNo,Status,InventoryType) VALUES (@d1,'Activate',@d2)"
69 cmd = New OleDbCommand(cb)
70 cmd.Parameters.AddWithValue("@d1", txtTableNo.Text)
71 cmd.Parameters.AddWithValue("@d2", cmbTableType.Text)
72 cmd.Connection = con
73 cmd.ExecuteReader()
74 con.Close()
75 Dim st As String = "added the new table '" & txtTableNo.Text & "'"
76 LogFunc(lblUser.Text, st)
77 MessageBox.Show("Successfully Saved", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
78 btnSave.Enabled = False
79 Getdata()
80 Reset()
81 Catch ex As Exception
82 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
83 End Try
84 End Sub
85
86 Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
87 If txtTableNo.Text = "" Then
88 MessageBox.Show("Please enter table no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
89 txtTableNo.Focus()
90 Return
91 End If
92 If cmbTableType.Text = "" Then
93 MessageBox.Show("Please select table type", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
94 cmbTableType.Focus()
95 Return
96 End If
97 Try
98 con = New OleDbConnection(cs)
99 con.Open()
100 Dim cb As String = "Update R_Table set TableNo=@d1,InventoryType=@d2 where TableNo=@d3"
101 cmd = New OleDbCommand(cb)
102 cmd.Connection = con
103 cmd.Parameters.AddWithValue("@d1", txtTableNo.Text)
104 cmd.Parameters.AddWithValue("@d2", cmbTableType.Text)
105 cmd.Parameters.AddWithValue("@d3", txtTable.Text)
106 cmd.ExecuteReader()
107 con.Close()
108 Dim st As String = "updated the table '" & txtTableNo.Text & "'"
109 LogFunc(lblUser.Text, st)
110 MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
111 btnUpdate.Enabled = False
112 Getdata()
113 Catch ex As Exception
114 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
115 End Try
116 End Sub
117 Private Sub DeleteRecord()
118
119 Try
120 Dim RowsAffected As Integer = 0
121 con = New OleDbConnection(cs)
122 con.Open()
123 Dim cl As String = "select R_Table.TableNo from R_Table,KOTgeneration where R_Table.TableNo=KOTgeneration.TableNo and R_Table.TableNo=@d1"
124 cmd = New OleDbCommand(cl)
125 cmd.Connection = con
126 cmd.Parameters.AddWithValue("@d1", txtTableNo.Text)
127 rdr = cmd.ExecuteReader()
128 If rdr.Read Then
129 MessageBox.Show("Unable to delete..Already in use in Billing", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
130 If Not rdr Is Nothing Then
131 rdr.Close()
132 End If
133 Exit Sub
134 End If
135 con.Close()
136 con = New OleDbConnection(cs)
137 con.Open()
138 Dim cl1 As String = "select R_Table.TableNo from R_Table,RestaurantBillingItems where R_Table.TableNo=RestaurantBillingItems.TableNo and R_Table.TableNo=@d1"
139 cmd = New OleDbCommand(cl1)
140 cmd.Connection = con
141 cmd.Parameters.AddWithValue("@d1", txtTableNo.Text)
142 rdr = cmd.ExecuteReader()
143 If rdr.Read Then
144 MessageBox.Show("Unable to delete..Already in use in Billing", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
145 If Not rdr Is Nothing Then
146 rdr.Close()
147 End If
148 Exit Sub
149 End If
150 con.Close()
151 con = New OleDbConnection(cs)
152 con.Open()
153 Dim cq As String = "delete from R_Table where TableNo=@d1"
154 cmd = New OleDbCommand(cq)
155 cmd.Parameters.AddWithValue("@d1", txtTable.Text)
156 cmd.Connection = con
157 RowsAffected = cmd.ExecuteNonQuery()
158 If RowsAffected > 0 Then
159 Dim st As String = "deleted the table '" & txtTableNo.Text & "'"
160 LogFunc(lblUser.Text, st)
161 MessageBox.Show("Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
162 Getdata()
163 Reset()
164 Else
165 MessageBox.Show("No Record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information)
166 Reset()
167 End If
168 If con.State = ConnectionState.Open Then
169 con.Close()
170
171 End If
172 Catch ex As Exception
173 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
174 End Try
175 End Sub
176 Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
177 Try
178 If MessageBox.Show("Do you really want to delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
179 DeleteRecord()
180 End If
181 Catch ex As Exception
182 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
183 End Try
184 End Sub
185
186 Private Sub dgw_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgw.MouseClick
187 Try
188 If dgw.Rows.Count > 0 Then
189 Dim dr As DataGridViewRow = dgw.SelectedRows(0)
190 txtTable.Text = dr.Cells(0).Value.ToString()
191 txtTableNo.Text = dr.Cells(0).Value.ToString()
192 cmbTableType.Text = dr.Cells(1).Value.ToString()
193 txtStatus.Text = dr.Cells(2).Value.ToString()
194 If dr.Cells(2).Value = "Activate" Then
195 btnActivate_Deactivate.Text = "Deactivate"
196 btnActivate_Deactivate.Enabled = True
197 End If
198 If dr.Cells(2).Value = "Deactivate" Then
199 btnActivate_Deactivate.Text = "Activate"
200 btnActivate_Deactivate.Enabled = True
201 End If
202 btnUpdate.Enabled = True
203 btnDelete.Enabled = True
204 btnSave.Enabled = False
205 End If
206 Catch ex As Exception
207 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
208 End Try
209 End Sub
210
211 Private Sub dgw_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgw.RowPostPaint
212 Dim strRowNumber As String = (e.RowIndex + 1).ToString()
213 Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
214 If dgw.RowHeadersWidth < Convert.ToInt32((size.Width + 20)) Then
215 dgw.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
216 End If
217 Dim b As Brush = SystemBrushes.ControlText
218 e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
219
220 End Sub
221 Public Sub Getdata()
222 Try
223 con = New OleDbConnection(cs)
224 con.Open()
225 cmd = New OleDbCommand("SELECT RTRIM(TableNo),InventoryType,RTRIM(Status) from R_Table order by TableNo", con)
226 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
227 dgw.Rows.Clear()
228 While (rdr.Read() = True)
229 dgw.Rows.Add(rdr(0), rdr(1), rdr(2))
230 End While
231 con.Close()
232 Catch ex As Exception
233 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
234 End Try
235 End Sub
236
237 Private Sub frmTable_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
238 If e.KeyCode = Keys.Enter Then
239 Me.SelectNextControl(Me.ActiveControl, True, True, True, False) 'for Select Next Control
240 End If
241 End Sub
242
243 Private Sub frmTableNo_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
244 Getdata()
245 fillInventoryType()
246 End Sub
247
248 Private Sub btnDeactivate_Click(sender As System.Object, e As System.EventArgs) Handles btnActivate_Deactivate.Click
249 If txtTableNo.Text = "" Then
250 MessageBox.Show("Please enter table no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
251 txtTableNo.Focus()
252 Return
253 End If
254
255 Try
256 con = New OleDbConnection(cs)
257 con.Open()
258 Dim cl3 As String = "select R_Table.TableNo from TempRestaurantPOS_OrderInfoKOT,R_Table where TempRestaurantPOS_OrderInfoKOT.TableNo=R_Table.TableNo and R_Table.TableNo=@d1"
259 cmd = New OleDbCommand(cl3)
260 cmd.Connection = con
261 cmd.Parameters.AddWithValue("@d1", txtTableNo.Text)
262 rdr = cmd.ExecuteReader()
263 If rdr.Read Then
264 MessageBox.Show("Unable to deactivate..Already in use in Restaurant POS", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
265 If Not rdr Is Nothing Then
266 rdr.Close()
267 End If
268 Exit Sub
269 End If
270 If btnActivate_Deactivate.Text = "Activate" Then
271 con = New OleDbConnection(cs)
272 con.Open()
273 Dim cb As String = "Update R_Table set TableNo=@d1,Status='Activate' where TableNo=@d2"
274 cmd = New OleDbCommand(cb)
275 cmd.Connection = con
276 cmd.Parameters.AddWithValue("@d1", txtTableNo.Text)
277 cmd.Parameters.AddWithValue("@d2", txtTable.Text)
278 cmd.ExecuteReader()
279 con.Close()
280 Dim st As String = "activated the table '" & txtTableNo.Text & "'"
281 LogFunc(lblUser.Text, st)
282 MessageBox.Show("Successfully activated", "Table", MessageBoxButtons.OK, MessageBoxIcon.Information)
283 btnActivate_Deactivate.Enabled = False
284 Getdata()
285 Reset()
286 End If
287 If btnActivate_Deactivate.Text = "Deactivate" Then
288 con = New OleDbConnection(cs)
289 con.Open()
290 Dim cb As String = "Update R_Table set TableNo=@d1,Status='Deactivate' where TableNo=@d2"
291 cmd = New OleDbCommand(cb)
292 cmd.Connection = con
293 cmd.Parameters.AddWithValue("@d1", txtTableNo.Text)
294 cmd.Parameters.AddWithValue("@d2", txtTable.Text)
295 cmd.ExecuteReader()
296 con.Close()
297 Dim st As String = "deactivated the table '" & txtTableNo.Text & "'"
298 LogFunc(lblUser.Text, st)
299 MessageBox.Show("Successfully deactivated", "Table", MessageBoxButtons.OK, MessageBoxIcon.Information)
300 btnActivate_Deactivate.Enabled = False
301 Getdata()
302 Reset()
303 End If
304 Catch ex As Exception
305 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
306 End Try
307 End Sub
308 End Class